#include<bits/stdc++.h>
using namespace std;
int a[50];
int ans=0;
void dfs(int x,int lb,int lg,int as,int n){
    if(x==n+1){ans=max(ans,as);return;}
    if(a[x]==a[lb]){
        dfs(x+1,x,lg,as+a[x],n);
    }
    else{
        dfs(x+1,x,lg,as,n);
    }
    if(a[x]==a[lg]){
        dfs(x+1,lb,x,as+a[x],n);
    }
    else{
        dfs(x+1,lb,x,as,n);
    }
}
void suan(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    ans=0;
    dfs(1,0,0,0,n);
    cout<<ans<<endl;
}
int main(){
	freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);
    int t;
    cin>>t;
    while(t--){
		suan();
    }
}
